﻿/**
 * 
 * Copyright 2009, 2010 Mike Jamer [email: mikejamer@gmail.com ]
 * 
 * This File is part of Moose IRC
 * 
 * MooseIRC is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * MooseIRC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with MooseIRC.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

using System;
using System.Collections.Generic;
using System.Text;
using moose.extension;
using moose.irc;

namespace moose.irc.standard.actions
{
    /// <summary>
    /// Responds to Notices
    /// </summary>
    [CLSCompliant(true)]
    [Action(
        Name = "moose-std-rsp-notice",
        Description = "Responds to notice messages",
        Author = "Mike MacKenzie-Jamer<email:mikejamer@gmail.com>",
        Version = "0.1",
        Type = ActionTypes.Response)]
    [Trigger(TriggerText = "NOTICE")]
    public sealed class NoticeResponse : IrcAction
    {
        public override IrcSessionStates valid_states()
        {
            return IrcSessionStates.Connected | IrcSessionStates.Registered;
        }

        public override void action(IrcSession session, IrcMessage message)
        {
            if (!session.Settings_Session.ContainsKey(IrcSessionSettings.RegistrationSent))
            {
                //Send the register command
                session.send("REGISTER");
            }

            //IF the source is null, then we assume the server is sending

            session.notify_event(
                new IrcEvent(IrcEventTypes.NoticeMessage,
                    new IrcEventArgument(IrcEventArgumentType.Message, message.Arguments[1]),
                    new IrcEventArgument(IrcEventArgumentType.SourceEntity, session.get_entity(message.Source)), //TODO: Review this, there are times when the source could be null, or non important,
                        //While I think it would already be supported with the existing object model, should consider instances where the server might be sending notices...
                    new IrcEventArgument(IrcEventArgumentType.DestinationEntity, session.get_entity(message.Arguments[0])) //This may not be an user, it could be a channel I think,
                                        //Might want to makea  .ToString hack or something, and use entities for this, to allow us to keep these methods alot more generic..
                    ));

            return;
        }
    }
}
